package com.teradyne.merlin2.ui.client.activities.util;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.PopupPanel.PositionCallback;
import com.teradyne.merlin2.ui.client.views.util.LoadingPopUpView;

public class LoadingPopUpActivity implements LoadingPopUpView.Presenter {
	private LoadingPopUpView view;

	
	public LoadingPopUpActivity(LoadingPopUpView view) {
		this.view = view;
	}

	@Override
	public void showAndSetPopupPosition() {
		view.getLoadingWidget().setPopupPositionAndShow(new PositionCallback() {

			@Override
			public void setPosition(int offsetWidth, int offsetHeight) {
				int left = (Window.getClientWidth() - offsetWidth) >> 1;
				int top = (Window.getClientHeight()- offsetHeight) >> 4;
				view.getLoadingWidget().setPopupPosition(Math.max(Window.getScrollLeft() + left, 0), Math.max(Window.getScrollTop() + top, 0));
			}
		});
	}

	@Override
	public void close() {
		view.getLoadingWidget().hide();
		
	}

	@Override
	public void setMessage(String message) {
		view.getLblMessage().setText(message);
	}

	@Override
	public void setAutoHide(boolean isAutoHide) {
		view.getLoadingWidget().setAutoHideEnabled(true);
	}


}